/**
 * 
 */
package com.sian.base.exception;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.core.Ordered;
import org.springframework.util.StopWatch;


/**
 * 捕获service层的异常并且不影响service事务层
 * @author 
 * @version 1.0  
 */
public class BaseException implements Ordered,MethodInterceptor{
   
	private int order; 
	private Log  log = LogFactory.getLog(BaseException.class);
	
	public int getOrder() {
		return this.order;
	}
	
	public void setOrder(int order) { 
		   this.order = order; 
	} 


	public Object profile(ProceedingJoinPoint call) throws Throwable { 
		
		Object returnValue; 
	
		StopWatch clock = new StopWatch(getClass().getName()); 
	
		try { 
	
		clock.start(call.toShortString()); 
		
		//抛出Service 中的异常到 struts
	    try{
		   returnValue = call.proceed(); 
	    }catch(Exception e){
	    	e.printStackTrace();//输出Service中的错误信息
	    	throw new Exception();
	    }
	    	
		} finally { 
	
		clock.stop(); 
	
		log.debug(clock.prettyPrint());//输出程序执行的sql的时间长度
	
		} 

	return returnValue; 

	}
	
	public Object invoke(MethodInvocation invocation) throws Throwable {

		log.debug("Before: invocation=[" + invocation + "]");
        Object rval = invocation.proceed();
        log.debug("Invocation returned");
        
        return rval;
	}

}
